<?php

/**
 * 获取用户的专业信息
 * User: yaosj
 * Date: 15-10-10
 * Time: 下午12:29
 */
class GetMajor implements iController
{

    public function output($queryArgs)
    {
        global $cmsdb;
        
        //学位返回大类，大类返回小类，小类返回专业
        if (empty($queryArgs['type'])|| !isset($queryArgs['code']))
            return genOutput(1000);

        $type = strtolower(trim($queryArgs['type']));
        $code = strtoupper(trim($queryArgs['code']));
        $returnArr = array();
        switch ($type) {

            case 'degree':
                $sql = 'SELECT major_code,major_name FROM data_major_list WHERE major_type = :code AND upper_code = "-"';
                //将code转化成Z\B\Y
                $codeArr = array(
                    0 => 'Z',
                    1 => 'B',
                    2 => 'Y',
                    3 => 'Y'
                );
                $code = $codeArr[$code];

                $results = $cmsdb->getResults($sql, array(':code' => $code));
                foreach ($results as $result) {
                    $returnArr[] = array(
                        'code' => $result->major_code,
                        'name' => $result->major_name
                    );
                }


                break;
            case 'top':
                $sql = 'SELECT major_code,major_name FROM data_major_list WHERE upper_code = :code';
                $results = $cmsdb->getResults($sql, array(':code' => $code));
                $returnArr[] = array('code' => 0, 'name' => '不限');
                foreach ($results as $result) {
                    $returnArr[] = array(
                        'code' => $result->major_code,
                        'name' => $result->major_name
                    );
                }

                break;
            case 'upper':
                $sql = 'SELECT major_code,major_name FROM data_major_list
 WHERE upper_code = :code';
                $results = $cmsdb->getResults($sql, array(':code' => $code));
                $returnArr[] = array('code' => 0, 'name' => '不限');
                foreach ($results as $result) {
                    $returnArr[] = array(
                        'code' => $result->major_code,
                        'name' => $result->major_name
                    );
                }
                break;

            default :
                return genOutput(1000);
        }

        return genOutput(1, array('data' => $returnArr));
    }
}